/*
 * Copyright (C) 2007-2008  Hylke van der Schaaf
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, in version 3 of the License.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package hextd.blackBox;

import hextd.core.Context;
import hextd.message.MessageTowerUpgrade;

/**
 *
 * @author hylke
 */
public class BBActionUpgradeTower implements BBAction {

	private static final BlackBox.ActionType type = BlackBox.ActionType.UpgradeTower;
	private int gameTime;
	private int activateTick;
	private int row;
	private int col;
	private int owner;

	/** Creates a new instance of BBActionUpgradeTower */
	public BBActionUpgradeTower(int gameTime, int row, int col, int activateTick, int owner) {
		this.gameTime = gameTime;
		this.activateTick = activateTick;
		this.row = row;
		this.col = col;
		this.owner = owner;
	}

	@Override
	public BlackBox.ActionType getType() {
		return BBActionUpgradeTower.type;
	}

	@Override
	public int getGameTime() {
		return this.gameTime;
	}

	@Override
	public void execute(Context c) {
		//System.out.println("BBActionNewTower::execute: "+c.gameTime+" Upgrading Tower.");
		if (!c.getBlackBox().upgradeTower(gameTime, col, row, activateTick, owner, false)) {
			System.err.println("BBActionUpgradeTower::execute: Sync error: Tower upgrade failed!");
		}
	}

	@Override
	public String getString() {
		return MessageTowerUpgrade.formatMessage(owner, gameTime, row, col);
	}
}
